#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:       JiChao_Song
    Date  :       2020/12/18 18:55
    Desc  :       用例集Model
--------------------------------------
"""
from bson import json_util

from application import mongo
from servers.models.ApiCaseModel import ApiCase


class ApiCaseSuite(mongo.Document):
    """
    测试机
    """

    caseSuiteName = mongo.StringField()
    caseList = mongo.ListField(mongo.StringField())
    projectId = mongo.StringField()
    runResponse = mongo.StringField()                   # 执行返回结果

    def caseListObject(self):
        apicaseArray = []
        if self.caseList:
            for i in self.caseList:
                apicaseArray.append(ApiCase.objects(id=i).first().to_json())

        return apicaseArray

    def to_json(self):

        return {
            '_id': eval(json_util.dumps(self.id)),
            'caseSuiteName': self.caseSuiteName,
            'caseList': self.caseListObject(),
            'projectId': self.projectId,
            'runResponse': self.runResponse,
        }